package com.edu.leetcode.dataStruct;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;

/**
 * 给定一个字符串，请你找出其中不含有重复字符的 最长子串 的长度。
 *
 * @作者 five-five
 * @创建时间 2021/4/10
 */
public class Demo15 {
    public static void main(String[] args) {
        Demo15 demo15 = new Demo15();
        int abcdera = demo15.lengthOfLongestSubstring("");
        System.out.println(abcdera);
    }

    /**
     * @param s
     * @return
     */
    public int lengthOfLongestSubstring(String s) {
        if (s == null || s.equals("")) {
            return 0;
        }
        int result = 1;
        for (int i = 0; i < s.length(); i++) {
            char temp = s.charAt(i);
            List<Character> characterList = new ArrayList<>();
            characterList.add(temp);
            for (int j = i + 1; j < s.length(); j++) {
                char c = s.charAt(j);
                boolean haveTheSome = this.isHaveTheSome(characterList, c);
                if (!haveTheSome) {
                    characterList.add(c);
                    result = Math.max(result, characterList.size());
                } else {
                    break;
                }
            }
        }
        return result;
    }

    /**
     * 判断一个集合中是否有相同的字符
     *
     * @param characterList
     * @param aim
     * @return
     */
    public boolean isHaveTheSome(List<Character> characterList, char aim) {
        for (Character character : characterList) {
            if (character.equals(aim)) {
                return true;
            }
        }
        return false;
    }
}
